import subprocess


def compile(file, language):
    if language == 'java':
        str = 'javac ' + file
    p = subprocess.Popen(str, shell=True, cwd='d:/', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    err = p.communicate()
    print err
    if p.returncode == 0:
        return True
    return False


myfile = 'Main.java'
if compile(myfile, 'java'):
    print 'compile successfully'
else:
    print 'compile failed'
